package com.cskaoyan.controller.wechat;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.user.FootPrint;
import com.cskaoyan.bean.user.FootPrintExample;
import com.cskaoyan.mapper.FootPrintMapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dengww
 * @create 2020/5/5 7:30
 */
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {

    @Autowired
    FootPrintMapper footPrintMapper;

    @GetMapping("list")
    public BaseRespVo getFootprintInfo() {
        FootPrintExample example =new FootPrintExample();
        List<FootPrint> list = footPrintMapper.selectByExample(example);
        Map<String,Object> map = new HashMap<>();
        long total = PageInfo.of(list).getTotal();
        map.put("totalPages",total);
        map.put("footprintList",list);
        return new BaseRespVo<>(0, map, "成功");
    }

    @PostMapping("delete")
    public BaseRespVo deleteFootprint(FootPrint footprint) {
        Date date = new Date();
        footprint.setUpdateTime(date);
        footprint.setDeleted(true);
        footPrintMapper.updateByPrimaryKeySelective(footprint);
        return new BaseRespVo<>(0, null, "成功");
    }
}
